<script type="text/javascript" >
    jQuery(".galleryVideo a[rel^='prettyPhoto']").prettyPhoto({
        theme:'facebook',
        keyboard_shortcuts: false
    });
    stYoutubeToolbox.sortColumn();
    stYoutubeToolbox.shortAction();    
    stYoutubeToolbox.loadMenuCallbackFunction = function () {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'x');
        data.addColumn('number', 'View');
        <?php
        $data = array();
        for($i=1; $i<=$day_count; $i++){
            $day_temp = ($i<10)? "0".$i:$i;
            $day = $day_temp.'-'.$month.'-'.$year;            
            if(!in_array($day, $date_history)){
                $date = $day;
                $data[$date] = "data.addRow([\"$date\", 0]);\n";
            }
        }
        if(count($results)>0){
            $yesterday_value = 0;
            foreach ($results as $result) {
                $value = $result->view - $yesterday_value;
                $day_temp = ($result->day<10)? "0".$result->day:$result->day;
                $month_temp = ($result->month<10)? "0".$result->month:$result->month;
                $date = $day_temp.'-'.$month_temp.'-'.$result->year;

                $data[$date] = "data.addRow([\"$date\", $value]);\n";

                $yesterday_value = $result->view;
            }
        }else{
            $data =false;
            echo 'stYoutubeToolboxCustom.drawVisualization(false);';
        }
        if($data){
            ksort($data);
            if(count($data)){
                foreach ($data as $value) {
                    echo $value;
                }
            }
            echo 'stYoutubeToolboxCustom.drawVisualization(data);';
        }
        ?>
       }
</script>

<div class="w100p bgl">
    <div class="w100p bgr">
        <div class="inner_container">
            <div class="filter">
                <label><?php _e('Videos', $config['plugin_name']) ?>:</label>
                <select id="stFilter"
                        onchange="
                            var data_post = new Array();
                            data_post['month'] = '<?php echo intval(date('m', $start_day)); ?>';
                            data_post['year'] = '<?php echo date('Y', $start_day); ?>';
                            data_post['filter'] = jQuery(this).val();
                            data_post['userFilter'] = jQuery('#stUserFilter').val();
                            stYoutubeToolbox.loadPage('<?php echo $current_action?>', data_post, false, function(){
                                stYoutubeToolbox.loadMenuCallbackFunction();
                            });
                        "
                >
                    <option <?php echo $filter == 'all' ? 'selected' : '' ?> value="all">All</option>                    
                    <?php                    
                    foreach ($videos as $value) {
                        if ($filter == $value->video_id) {
                            $select = 'selected';
                        } else {
                            $select = '';
                        }
                    ?>
                        <option <?php echo $select ?> value="<?php echo $value->video_id ?>"><?php echo $value->title ?></option>
                    <?php
                    }
                    ?>
                </select>
                <label><?php _e('Select account', $config['plugin_name']) ?>:</label>
                <select id="stUserFilter" onchange="
                            var data_post = new Array();
                            data_post['month'] = '<?php echo intval(date('m', $start_day)); ?>';
                            data_post['year'] = '<?php echo date('Y', $start_day); ?>';
//                            data_post['filter'] = jQuery('#stFilter').val();
                            data_post['userFilter'] = jQuery(this).val();
                            stYoutubeToolbox.loadPage('<?php echo $current_action?>', data_post, false, function(){
                                stYoutubeToolbox.loadMenuCallbackFunction();
                            });
                        "
                >
                    <option <?php echo $userFilter == 0 ? 'selected' : '' ?> value="0">All account</option>

                    <?php
                    foreach ($users as $user) {
                        if ($userFilter == $user->id) {
                            $select = 'selected';
                        } else {
                            $select = '';
                        }
                    ?>
                        <option <?php echo $select ?> value="<?php echo $user->id ?>"><?php echo $user->user_name ?></option>
                    <?php
                    }
                    ?>
                </select>
                <br clear="both" />
                <?php if(!empty($video_filter[0]->title)){ ?>
                <div class="galleryVideo">
                <label>Title:</label> <?php echo $video_filter[0]->title?><br clear="both" />
                <a href="http://www.youtube.com/watch?v=<?php echo $video_filter[0]->video_id?>" rel="prettyPhoto" title="">
                    <img height='70' src='<?php echo $video_filter[0]->thumbnail_url?>' alt='' />
                </a>
                </div>
                <?php }?>
            </div>
            <br clear="both" />
            <center>
                <div id="chartDiv"></div>
                <div align="center" id="month" style="width:160px;">
                    <span
                        onclick="
                            var data_post = new Array();
                            data_post['month'] = '<?php echo intval(date('m', $start_day)) - 1; ?>';
                            data_post['year'] = '<?php echo date('Y', $start_day); ?>';
                            data_post['filter'] = jQuery('#stFilter').val();
                            stYoutubeToolbox.loadPage('<?php echo $current_action?>', data_post, false, function(){
                                stYoutubeToolbox.loadMenuCallbackFunction();
                            });"
                        class="arrow_left" >
                    </span>
                    <span id="facebook_like_month"><?php echo date('F', $start_day); ?>, </span>&nbsp;
                    <span id="facebook_like_year"><?php echo date('Y', $start_day); ?></span>&nbsp;
                    <span 
                        onclick="
                            var data_post = new Array();
                            data_post['month'] = '<?php echo intval(date('m', $start_day)) + 1; ?>';
                            data_post['year'] = '<?php echo date('Y', $start_day); ?>';
                            data_post['filter'] = jQuery('#stFilter').val();
                            stYoutubeToolbox.loadPage('<?php echo $current_action?>', data_post, false, function(){
                                stYoutubeToolbox.loadMenuCallbackFunction();
                            });"
                        
                          class="arrow_right" >
                    </span>

                </div>
                <br clear="both" />
            </center>
            <table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stYoutubeToolbox_statistic'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    $tr_class = "";
                    foreach ($results as $result) {
                        if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        echo "<tr $tr_class >"
//                        . "<td>" . $result->title . "</td>"
//                        . "<td><img height='50' src='" . $result->thumbnail . "' alt='' /></td>"
                        . "<td>" . $result->cdate . "</td>"
                        . "<td>" . $result->view . "</td>"                        
                        . "</tr>"
                        ;
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>

        </div>
    </div>
</div>